/**
 *  @file BitAttribute.h
 */
#ifndef _BITATTRIBUTE_H_
#define _BITATTRIBUTE_H_

#include "../common/BaseObject.h"

namespace cppflib
{

namespace util
{

/**
 *  Class to encapsulate an attribute bitmap
 */
template <typename ATTRTYPE>
class BitAttributeT : public BaseObject
{
private:
   u32_t attr;

public:
   BitAttributeT()
   {
      attr = 0;
   }
   
   virtual ~BitAttributeT()
   {
   }

   bool IsAttrSet(ATTRTYPE t)
   {
      return ((attr & static_cast<u32_t>(t)) != 0);
   }

   void SetAttr(ATTRTYPE t, bool isEnableAttr)
   {
      if (isEnableAttr)
         attr |= static_cast<u32_t>(t);
      else 
         attr &= ~static_cast<u32_t>(t);
   }

   /**
    *  Remove all previous values and directly set to this attribute
    */
   void Replace(ATTRTYPE t)
   {
      attr = static_cast<u32_t>(t);
   }
};


} // end of namespace util

} // end of namespace cppflib

#endif
